* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: #f5f5f5;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 聊天容器 */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  margin: 0;
  background: #ffffff;
}

/* 聊天头部 */
.chat-header {
  padding: 20px 24px;
  background: #ffffff;
  border-bottom: 1px solid #e8e8e8;
}

.chat-header h1 {
  font-size: 20px;
  margin-bottom: 4px;
  color: #1a1a1a;
}

.chat-header p {
  font-size: 13px;
  color: #666;
}

/* 消息区域 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #fafafa;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
  font-size: 16px;
}

/* 消息 */
.message {
  display: flex;
  margin-bottom: 20px;
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-user {
  flex-direction: row-reverse;
}

.message-user .message-content {
  background: #667eea;
  color: white;
  border-radius: 12px;
}

.message-assistant .message-content {
  background: white;
  color: #333;
  border-radius: 12px;
  border: 1px solid #e8e8e8;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin: 0 12px;
  flex-shrink: 0;
  background: #f0f0f0;
}

.message-content {
  max-width: 70%;
  padding: 12px 16px;
  word-wrap: break-word;
  position: relative;
}

.message-user .message-content {
  text-align: left;
}

.text-content {
  white-space: pre-wrap;
  line-height: 1.6;
}

/* Markdown 样式 */
.markdown-body {
  line-height: 1.6;
  color: inherit;
}

.markdown-body p {
  margin-bottom: 12px;
}

.markdown-body p:last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 20px;
  margin-bottom: 10px;
  font-weight: 600;
  color: inherit;
}

.markdown-body h1 {
  font-size: 2em;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  padding-bottom: 8px;
}

.markdown-body h2 {
  font-size: 1.5em;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  padding-bottom: 8px;
}

.markdown-body ul,
.markdown-body ol {
  margin-bottom: 12px;
  padding-left: 24px;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.markdown-body pre {
  background: #f6f8fa;
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: #24292e;
}

.markdown-body blockquote {
  border-left: 4px solid #667eea;
  padding-left: 16px;
  margin: 12px 0;
  color: #666;
  font-style: italic;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 12px;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.markdown-body th {
  background: #f5f5f5;
  font-weight: 600;
}

.markdown-body a {
  color: #667eea;
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 12px 0;
  display: block;
}

/* 输入区域 */
.chat-input-container {
  display: flex;
  padding: 16px 20px;
  background: white;
  border-top: 1px solid #e0e0e0;
  gap: 12px;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: #667eea;
}

.chat-input:disabled {
  background: #f5f5f5;
  cursor: not-allowed;
}

.send-button {
  position: relative;
  padding: 12px 32px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-position 0.4s ease;
  background-size: 200% auto;
}

.send-button::after {
  content: '';
  position: absolute;
  top: 0;
  left: -120%;
  width: 120%;
  height: 100%;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.35) 45%, rgba(255, 255, 255, 0) 90%);
  transform: skewX(-20deg);
  transition: transform 0.5s ease, left 0.5s ease, opacity 0.5s ease;
  opacity: 0;
}

.send-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.35);
  background-position: right center;
}

.send-button:hover:not(:disabled)::after {
  left: 120%;
  opacity: 1;
}

.send-button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 12px rgba(102, 126, 234, 0.2);
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.stop-button {
  position: relative;
  padding: 12px 32px;
  background: #fff6f5;
  color: #ff4d4f;
  border: 1px solid rgba(255, 77, 79, 0.4);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: stop-pulse 1.6s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.25);
}

.stop-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 77, 79, 0.25);
}

.stop-button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 3px 12px rgba(255, 77, 79, 0.2);
}

.stop-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  animation: none;
  box-shadow: none;
}

@keyframes stop-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.28);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(255, 77, 79, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 77, 79, 0);
  }
}

/* 思考动画 */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #999;
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0s;
}

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.7;
  }
  40% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .chat-container {
    height: 100vh;
    width: 100%;
  }

  .message-content {
    max-width: 85%;
  }

  .chat-input-container {
    padding: 12px;
  }

  .send-button {
    padding: 12px 24px;
  }
}

.layout {
  display: flex;
  height: 100vh;
}

.session-sidebar {
  width: 260px;
  border-right: 1px solid #e8e8e8;
  background: #fafafa;
  display: flex;
  flex-direction: column;
}

.session-header {
  padding: 20px 16px;
  font-weight: 600;
  background: #f5f7fa;
  border-bottom: 1px solid #e8e8e8;
}

.session-create {
  display: flex;
  gap: 8px;
  padding: 12px 12px;
  border-bottom: 1px solid #e8e8e8;
}

.session-input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
}

.session-create-btn {
  padding: 8px 12px;
  border: none;
  background: #667eea;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
}

.session-list {
  flex: 1;
  overflow: auto;
}

.session-empty {
  padding: 12px;
  color: #888;
}

.session-item {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.2s;
}

.session-item:hover {
  background: #f5f5f5;
}

.session-item.active {
  background: #f5f7ff;
}

.session-title .pin {
  margin-right: 6px;
}

.session-actions button {
  margin-left: 8px;
}

.session-actions .link {
  background: transparent;
  border: none;
  color: #667eea;
  cursor: pointer;
}

.session-actions .danger {
  background: transparent;
  border: none;
  color: #e74c3c;
  cursor: pointer;
}

.main {
  flex: 1;
}

.session-toolbar {
  padding: 8px 12px;
  border-bottom: 1px solid #f0f0f0;
}

.chat-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: #fff;
  border-top: 1px solid #eaeaea;
  border-bottom: 1px solid #eaeaea;
}

.tool-btn {
  padding: 6px 10px;
  border: 1px solid #ddd;
  background: #fafafa;
  border-radius: 6px;
  cursor: pointer;
}

.tool-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.modal {
  position: fixed;
  left: 0; top: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal.show { display: flex; }
.modal-content {
  width: 720px;
  max-width: 92vw;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
}
.modal-title { font-weight: 600; }
.modal-close { margin-left: auto; border: none; background: transparent; font-size: 20px; cursor: pointer; }
.modal-body { padding: 12px 16px; max-height: 70vh; overflow: auto; }
.modal-footer { display: flex; padding: 12px 16px; border-top: 1px solid #eee; }

.settings-form .form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.settings-form .form-row.inline { flex-direction: row; align-items: center; gap: 12px; }
.settings-form textarea { width: 100%; padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px; }
.settings-form select { width: 220px; padding: 6px 8px; border: 1px solid #ddd; border-radius: 6px; }
.settings-form input[type="range"] { width: 220px; }
.image-url-box { display: flex; gap: 8px; }
.image-input { flex: 1; padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px; }
.image-list { list-style: none; padding: 0; margin: 8px 0 0; }
.image-list li { display: flex; gap: 8px; align-items: center; padding: 6px 0; }
.url-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 工具调用和工具结果样式 */
.tool-calls-container,
.tool-result-container {
  margin: 8px 0;
  border-radius: 8px;
  overflow: hidden;
  background: #f8f9fa;
  border: 1px solid #e1e4e8;
}

.tool-calls-header,
.tool-result-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e8ebf0 100%);
  cursor: pointer;
  user-select: none;
  transition: background 0.2s ease;
}

.tool-calls-header:hover,
.tool-result-header:hover {
  background: linear-gradient(135deg, #eaeef3 0%, #dfe3e9 100%);
}

.tool-icon {
  font-size: 16px;
  margin-right: 8px;
}

.tool-label {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: #24292e;
}

.tool-toggle {
  font-size: 12px;
  color: #586069;
  margin-left: 8px;
  transition: transform 0.2s ease;
}

.tool-calls-content,
.tool-result-content {
  padding: 12px;
  background: #ffffff;
  border-top: 1px solid #e1e4e8;
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tool-call-item {
  padding: 8px 0;
}

.tool-call-item:not(:last-child) {
  border-bottom: 1px solid #f0f0f0;
  margin-bottom: 8px;
  padding-bottom: 12px;
}

.tool-call-name,
.tool-result-name {
  font-size: 13px;
  margin-bottom: 6px;
  color: #24292e;
}

.tool-call-name strong,
.tool-result-name strong {
  color: #0366d6;
  margin-right: 4px;
}

.tool-call-args,
.tool-result-data {
  font-size: 12px;
  color: #586069;
}

.tool-call-args strong,
.tool-result-data strong {
  color: #0366d6;
  margin-right: 4px;
  display: block;
  margin-bottom: 4px;
}

.tool-call-args pre,
.tool-result-data pre {
  background: #f6f8fa;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 4px 0 0;
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #24292e;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.tool-result-data pre {
  color: #22863a;
}

/* 当工具消息在用户消息中时(理论上不会出现,但保险起见) */
.message-user .tool-calls-container,
.message-user .tool-result-container {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.message-user .tool-calls-header,
.message-user .tool-result-header {
  background: rgba(255, 255, 255, 0.15);
}

.message-user .tool-calls-header:hover,
.message-user .tool-result-header:hover {
  background: rgba(255, 255, 255, 0.25);
}

.message-user .tool-label {
  color: white;
}

.message-user .tool-toggle {
  color: rgba(255, 255, 255, 0.8);
}

.message-user .tool-calls-content,
.message-user .tool-result-content {
  background: rgba(255, 255, 255, 0.1);
  border-top-color: rgba(255, 255, 255, 0.2);
}

.message-user .tool-call-name,
.message-user .tool-result-name,
.message-user .tool-call-args,
.message-user .tool-result-data {
  color: white;
}

.message-user .tool-call-name strong,
.message-user .tool-result-name strong,
.message-user .tool-call-args strong,
.message-user .tool-result-data strong {
  color: rgba(255, 255, 255, 0.95);
}
